/*
 * @Author: 姚潘涛
 * @Date: 2024-04-08 20:36:39
 * @LastEditors: 姚潘涛
 * @LastEditTime: 2024-04-10 10:30:40
 * @FilePath:
 * /xict_ws/src/xcmg-intelligent-cockpit-three/src/xict_ui/include/xict_ui_core/vehiclemanage.h
 * @Description:
 *
 * Copyright (c) 2024 by pandaman, All Rights Reserved.
 */
#ifndef VEHICLEMANAGE_H
#define VEHICLEMANAGE_H

#include "xict_ui_common/utils/net_tool.h"
#include "xict_ui_common/utils/utils.h"
#include "xict_ui_core/imageitem.h"
#include "xict_ui_driver/utils/basecansdk.h"
#include "xict_ui_driver/utils/baseimgsdk.h"
#include <QJsonArray>
#include <QJsonDocument>
#include <QJsonObject>
#include <QMap>
#include <QThread>

namespace xict_ui_core {

    enum VehicleType { GRADER = 0, LOADER };

    class VehicleManage : public QThread {
        Q_OBJECT

        //    Q_PROPERTY(bool connect_flag READ get_connect_flag WRITE
        //    set_connect_flag); // false: 未连接车辆 true: 已连接车辆
        BJ_PROPERTY(bool, run_flag);
        BJ_PROPERTY(bool, connect_flag);
        BJ_PROPERTY(QString, current_vehicle_name);
        BJ_PROPERTY(QString, current_vehicle_type);
        BJ_PROPERTY(QString, current_vehicle_host);

        // public:
        //    void set_connect_flag(bool flag){
        //        if(m_connect_flag == flag && image_thread_ptr_ != nullptr)
        //            return;
        //        m_connect_flag = flag;
        //        if(m_connect_flag)
        //            createImageThread();
        ////        net_tool_->start();
        //    }

        //    bool get_connect_flag(){
        //        return m_connect_flag;
        //    }

    public:
        static VehicleManage* getInstance();

        enum VehicleType { GRADER = 0, LOADER, BLADER };

        Q_ENUM(VehicleType);

        VehicleManage(QObject* parent = nullptr);
        void init(QString json_path = "");
        void run() override;

        //    Q_INVOKABLE bool connectImageItem(ImageItem* item, int
        //    image_type); Q_INVOKABLE void enableImageThread(); Q_INVOKABLE
        //    void disableImageThread();

    signals:
        void signalVehiclesInfo(QString data);
        void signalVehiclePingTime(QString ping_time);

    protected:
        bool createImageThread();

    private:
        //    bool m_connect_flag = false;
        QString m_cfg_path;
        QJsonArray vehicleArray;   // TODO: array 转 map
        QMap<QString, QString> vehicleHostMap;
        QList<QMap<QString, QString> > vehicleStateList;
        //    bool run_flag = true;
        int m_vehicle_type = 0;

        //    std::unique_ptr<xict_ui_driver::BaseImageThread>
        //    image_thread_ptr_{}; std::unique_ptr<xict_ui_driver::BaseCanSdk>
        //    can_thread_ptr_{};

        xict_ui_common::NetTool net_tool_;
    };

}   // namespace xict_ui_core

#endif   // VEHICLEMANAGE_H
